//
//  CYUrltestVC.m
//  CreditAddressBook
//
//  Created by Mosu&Cuu on 16/7/11.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "CYUrltestVC.h"
#import "CYHttpTool.h"
#import "CYJsonInfo.h"
#import "NSObject+MJKeyValue.h"
#import "MBProgressHUD+LE.h"
#import "CXCarouselView.h"
#import "CYUser.h"
#import "CYLoginHttpTool.h"
#import "LEPhotoBrowserTool.h"
#import "CYImageShowView.h"
#import "UIImageView+WebCache.h"
#import "SDImageCache.h"

@interface CYUrltestVC ()
@property (nonatomic, strong)NSArray *detailArr;
@property (nonatomic, strong) NSMutableArray *DetialImgHeigths;
@property (nonatomic, strong) NSMutableArray *DetialImgWides;


@end

@implementation CYUrltestVC

- (void)viewDidLoad {
    [super viewDidLoad];
     _DetialImgWides = [[NSMutableArray alloc]init];
     _DetialImgHeigths = [[NSMutableArray alloc]init];
     
     [self loadimage];
    // Do any additional setup after loading the view from its nib.
}

-(void)loadimage{
     [CYHttpTool postWithURL:[CYURL shared].getZhifubao params:@{} success:^(id json) {
          CYJsonInfo *jsoninfo = [CYJsonInfo objectWithKeyValues:json];
          NSDictionary *dic = jsoninfo.data;
          _detailArr = [dic objectForKey:@"pics"];
          [self loadiamgeView];
          
     } failure:^(NSError *error) {
          
     }];

}

-(void)loadiamgeView{
     dispatch_queue_t queue = dispatch_queue_create("cn.xxx.queue", DISPATCH_QUEUE_SERIAL);
     
                  [_detailArr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
          
                          // 开启异步函数，获取下载图片，获取尺寸
                          dispatch_async(queue, ^{
                                    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:obj]];
                                    UIImage *image = [UIImage imageWithData:data];
                                    CGSize imgSize = image.size;
                                    [_DetialImgHeigths addObject:@(imgSize.height)];
                                    [_DetialImgWides addObject:@(imgSize.width)];
                               CYLog(@"_heights = %@",_DetialImgHeigths);
                               CYLog(@"_width = %@",_DetialImgWides);
                                    // 回到主线程执行
                                    dispatch_sync(dispatch_get_main_queue(), ^(){
               
                                         });
                                });
                      
                       
                  }];
     
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
